﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="House客户端.Register" %>

<!DOCTYPE html>
<html>
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>信息登记页面</title>
    <link href="jquery-easyui-1.5.2/themes/default/easyui.css" rel="stylesheet" />
    <link href="easyui/css/wu.css" rel="stylesheet" />
    <link href="easyui/css/icon.css" rel="stylesheet" />
</head>
<body>
    <div class="easyui-panel" fit="true">
        <table>
            <tr>
                <td>借款人员基本信息</td>
            </tr>
            <tr id="Borrower">
                <td>借款人姓名:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" class="easyui-textbox" required name="borrowername" placeholder="请输入借款人姓名" /></td>
                <td>身份证号:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" class="easyui-textbox" required name="borrowerid" placeholder="请输入身份证号" /><span style="color: red" id="sp1"></span></td>
                <td>联系电话:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" class="easyui-textbox" required name="borrowertel" placeholder="请输入联系电话" /><span style="color: red" id="sp2"></span></td>
                <td>
                    <a href="#" class="easyui-linkbutton" id="addbutton" onclick="adduser()">添加借款人</a></td>
            </tr>
            <tr>
                <td colspan="4">联系人：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="text" required style="width: 800px;" class="easyui-textbox" id="Contacts" placeholder="请输入联系人" />
                    <span style="color: red" id="sp5"></span>
                </td>
            </tr>
            <tr>
                <td colspan="4">联系电话：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="text" required id="Contactstel" class="easyui-textbox" style="width: 800px;" placeholder="请输入联系电话" />
                    <span style="color: red" id="sp3"></span>
                </td>
            </tr>
            <tr>
                <td colspan="4">房屋剩余年限：
                    <input type="text" style="width: 800px;" required class="easyui-textbox" id="RemainingYears" placeholder="请输入房屋剩余年限" />
                    <span style="color: red" id="sp6"></span>
                </td>
            </tr>
            <tr>
                <td colspan="4">贷款额度(万元)：
                    <input type="text" class="easyui-textbox" required style="width: 800px;" id="Loanlimit" placeholder="请输入贷款额度，单位为万元" />
                    <span style="color: red" id="sp7"></span>
                </td>
            </tr>
            <tr>
                <td colspan="4">房屋坐落：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <input type="text" required class="easyui-textbox" style="width: 800px;" id="HouseIsLocated" placeholder="请输入房屋坐落" />
                    <span style="color: red" id="sp8"></span>
                </td>
            </tr>
            <tr>
                <td colspan="4">房屋用途：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <select id="Purpose" class="easyui-combobox" required style="width: 800px;">
                      <option value="请选择房屋用途"></option>
                  </select>

                </td>
            </tr>
            <tr>
                <td colspan="4">建成年代：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="text" class="easyui-textbox" required style="width: 800px;" id="BuiltYears" placeholder="请输入建成年代" />
                    <span style="color: red" id="sp9"></span>
                </td>
            </tr>
            <tr>
                <td colspan="4">建成年代来源：
                  <select id="Sourse" class="easyui-combobox" required style="width: 800px;">
                      <option value="请选择建成年代来源"></option>
                  </select>
                </td>
            </tr>
            <tr>
                <td colspan="4">报告类型：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                     <select id="Type" style="width: 800px;" required class="easyui-combobox">
                         <option value="请选择报告类型"></option>
                     </select>
                </td>
            </tr>
            <tr>
                <td colspan="4">评估受理：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                   <input type="checkbox" value="审核评估登记表" />审核评估登记表
                   <input type="checkbox" value="身份证明" />身份证明
                   <input type="checkbox" value="房屋产权" />房屋产权
                   <input type="checkbox" value="网签合同" />网签合同
                </td>
            </tr>
            <tr>
                <td colspan="4">所属部门：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <select id="deptartment" style="width: 800px;" required class="easyui-combobox">
                        <option value="请选择所属部门"></option>
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="4">勘查员：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      <select id="Survey" class="easyui-combobox" required style="width: 800px;">
                          <option value="请选择勘察员"></option>
                      </select>
                </td>
            </tr>
            <tr>
                <td colspan="4">估价员：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      <select id="Evaluation" class="easyui-combobox" required style="width: 800px;">
                          <option value="请选择估价员"></option>
                      </select>
                </td>
            </tr>
            <tr>
                <td colspan="4">评估通知单出具日期：
                    <input type="date" class="easyui-textbox" required id="Issue_Time" style="width: 770px;" />

                </td>
            </tr>
            <tr>
                <td>
                    <a href="#" class="easyui-linkbutton" onclick="funadd()">登记</a>
                </td>
            </tr>
        </table>
    </div>
    <script src="jquery-easyui-1.5.2/jquery.min.js"></script>
    <script src="jquery-easyui-1.5.2/jquery.easyui.min.js"></script>
    <script src="jquery-easyui-1.5.2/locale/easyui-lang-zh_CN.js"></script>
    <script src="jquery-easyui-1.5.2/easyloader.js"></script>
    <script src="jquery-easyui-1.5.2/Common.js"></script>
    <script>
        //加载事件
        $(function () {
            Use();
            laiyuan();
            type();
            //绑定房屋用途下拉框
            function Use() {
                $.ajax({
                    type: "get",
                    url: WebApiURL + "api/Dictionary/?type=" + "房屋用途" + "&i=" + 1,
                    success: function (obj) {
                        obj = eval(obj);
                        $("#Purpose").combobox({
                            editable: false,
                            data: obj,
                            valueField: "Dictionary_Name",
                            textField: 'Dictionary_Name'
                        });
                    }
                });
            };
            //建成年代来源绑定
            function laiyuan() {
                $.ajax({
                    type: "Get",
                    url: WebApiURL + "api/Dictionary/?type=" + "建成年代来源" + "&i=" + 27,
                    success: function (obj) {
                        obj = eval(obj);
                        $("#Sourse").combobox({
                            editable: false,
                            data: obj,
                            valueField: "Dictionary_Name",
                            textField: "Dictionary_Name"
                        })
                    }
                });
            };
            //报告类型绑定
            function type() {
                $.ajax({
                    type: "Get",
                    url: WebApiURL + "api/Dictionary/?type=" + "报告类型" + "&i=" + 40,
                    success: function (obj) {
                        obj = eval(obj);
                        $("#Type").combobox({
                            editable: false,
                            data: obj,
                            valueField: "Dictionary_Name",
                            textField: "Dictionary_Name"
                        })
                    }
                });
            };
        });
        //添加多个借款人
        $(function () {
            $("#addbutton").click(function () {
                $("#Borrower").after("<tr><td>借款人姓名:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"text\" name=\"borrowername\" placeholder=\"请输入借款人姓名\" \"required\" /></td><td>身份证号:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"text\" name=\"borrowerid\" placeholder=\"请输入身份证号\" required /></td><td>联系电话:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"text\" name=\"borrowertel\" placeholder=\"请输入联系电话\" required /></td><td><button onclick=\"delTableRow(this)\">删除借款人</button></td></tr>");
            });
        });
        //移除多个借款人
        function delTableRow(obj) {
            $(obj).parent().parent().remove();
        }
        // 绑定部门表的信息
        $.ajax({
            type: "Get",
            url: WebApiURL + "api/Department",
            success: function (obj) {
                obj = eval(obj);
                $("#deptartment").combobox({
                    editable: false,
                    data: obj,
                    valueField: "ID",
                    textField: "Department_Name",
                    onChange: function (newvalue) {
                        kancha(newvalue);
                        pinggu(newvalue);
                    }
                });
            }
        });
        //绑定勘察员下拉框
        function kancha(newvalue) {
            $.ajax({
                type: "get",
                url: WebApiURL + "api/User_Dept/?id=" + newvalue,
                dataType: "json",
                success: function (obj) {
                    editable: false,
                    obj = eval(obj);
                    $("#Survey").combobox({
                        editable: false,
                        data: obj,
                        valueField: "Users_Name",
                        textField: "Users_Name",
                    })
                }
            })
        };
        //绑定评估员下拉框
        function pinggu(newvalue) {
            $.ajax({
                type: "post",
                url: WebApiURL + "api/User_Dept/?id=" + newvalue,
                dataType: "json",
                success: function (obj) {
                    if (obj != null) {
                        obj = eval(obj);
                        $("#Evaluation").combobox({
                            editable: false,
                            data: obj,
                            valueField: "Users_Name",
                            textField: "Users_Name",
                        })
                    }
                }
            });
        };
        ///添加到登记表
        function funadd() {
            //房屋剩余年限
            var RemainingYears = $("#RemainingYears").val();
            if (RemainingYears == "" || RemainingYears == null) {
                $("#sp6").html("不能为空");
                return;
            } else {
                $("#sp6").html("");
            }
            //贷款额度
            var Loanlimit = $("#Loanlimit").val();
            if (Loanlimit == "" || Loanlimit == null) {
                $("#sp7").html("不能为空");
                return;
            } else {
                $("#sp7").html("");
            }
            ///房屋坐落
            var HouseIsLocated = $("#HouseIsLocated").val();
            if (HouseIsLocated == "" || HouseIsLocated == null) {
                $("#sp8").html("不能为空");
                return;
            } else {
                $("#sp8").html("");
            }
            ///房屋用途 
            var Purpose = $("#Purpose").combobox('getValue');
            if (Purpose == "请选择房屋用途") {
                $.messager.alert("提示", "请选择房屋用途！");
                return;
            }
            ///建成年代
            var BuiltYears = $("#BuiltYears").val();
            if (BuiltYears == "" || BuiltYears == null) {
                $("#sp9").html("不能为空");
                return;
            } else {
                $("#sp9").html("");
            }
            ///建成年代来源
            var Sourse = $("#Sourse").combobox('getValue');
            if (Sourse == "请选择建成年代来源") {
                $.messager.alert("提示", "请选择建成年代来源！");
                return;
            }
            ///报告类型
            var Type = $("#Type").combobox('getValue');
            if (Type == "请选择报告类型") {
                $.messager.alert("提示", "请选择报告类型！");
                return;
            }
            ///评估受理
            var Assessment = "";
            $(":checkbox:checked").each(function () {
                Assessment += $(this).val() + ",";
            });
            Assessment = Assessment.substr(0, Assessment.length - 1);
            //部门信息
            var deptartment = $("#deptartment").combobox('getText');

            //勘察员
            var Survey = $("#Survey").combobox('getValue');
            //估价员
            var Evaluation = $("#Evaluation").combobox('getValue');
            //评估通知单出具日期
            var Issue_Time = $("#Issue_Time").val();
            if (RemainingYears == "" || RemainingYears == null || Loanlimit == "" || Loanlimit == null || HouseIsLocated == "" || HouseIsLocated == null || BuiltYears == "" || BuiltYears == null || Issue_Time == "" || Issue_Time == null) {
                $.messager.alert("提示", "信息不可为空！");
                return;
            }
            ///借款人
            var _borrowername = "";
            var borrowername = document.getElementsByName("borrowername");
            for (var i = 0; i < borrowername.length; i++) {
                _borrowername += borrowername[i].value + ",";
            }
            _borrowername = _borrowername.substr(0, _borrowername.length - 1);
            ///借款人身份证号
            var _borrowerid = "";
            var borrowerid = document.getElementsByName("borrowerid");
            var regborrowerid = /^(\d{18}|\d{17}x)$/;    //验证身份证是否合法

            for (var i = 0; i < borrowerid.length; i++) {
                _borrowerid += borrowerid[i].value + ",";
            }
            _borrowerid = _borrowerid.substr(0, _borrowerid.length - 1);

            if (!regborrowerid.test(_borrowerid)) {
                $("#sp1").html("身份证不合法");
                return;
            }
            else {
                $("#sp1").html("");
            }
            //借款人联系电话
            var _borrowertel = "";
            var borrowertel = document.getElementsByName("borrowertel");
            var regphoto = /^1(3|5|7|8)\d{9}$/;  //验证手机号是否合法

            for (var i = 0; i < borrowertel.length; i++) {
                _borrowertel += borrowertel[i].value + ",";
            }
            _borrowertel = _borrowertel.substr(0, _borrowertel.length - 1);
            if (!regphoto.test(_borrowertel)) {
                $("#sp2").html("手机号不合法");
                return;
            } else {
                $("#sp2").html("");
            }
            //联系人姓名
            var Contacts = $("#Contacts").val();
            if (Contacts == "" || Contacts == null) {
                $("#sp5").html("不能为空");
                return;
            } else {
                $("#sp5").html("");
            }
            //联系人电话
            var Contactstel = $("#Contactstel").val();

            if (!regphoto.test(Contactstel)) {
                $("#sp3").html("手机号不合法");
                return;
            } else {
                $("#sp3").html("");
            }
            $.ajax({
                type: "post",
                url: WebApiURL + "api/Register/AddEABasicInfo",
                data: {
                    Loan_Name: _borrowername,
                    Loan_IdCard: _borrowerid,
                    Loan_TEL: _borrowertel,
                    Loan_Contacts: Contacts,
                    Loan_ContactsTEL: Contactstel,
                    Issue_Time: Issue_Time,
                    Evaluation: Evaluation,
                    Survey: Survey,
                    The_Department: deptartment,
                    Presentation_Type: Type,
                    Assessment: Assessment,
                    Yers_Source: Sourse,
                    House_Time: BuiltYears,
                    House_Purpose: Purpose,
                    House_Located: HouseIsLocated,
                    Surplus_Years: RemainingYears,
                    Basic_Quota: Loanlimit,
                    Create_People: "admin",
                },
                success: function (result) {
                    if (result) {
                        $.messager.alert("温馨提示", '添加成功!');
                        setTimeout('location.href = \'RegisterList.aspx\'', 1000);
                    } else {
                        $.messager.alert("温馨提示", '添加失败!');
                    }
                }
            });
        };
    </script>
</body>
</html>
